/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import pojos.Articulos;

/**
 *
 * @author dam2A
 */
public class ArticulosTableModel extends AbstractTableModel{
    
    ArrayList<Articulos> alArticulos;
    ArrayList<String> nomcols;

    public ArticulosTableModel(ArrayList<Articulos> alArticulos, ArrayList<String> nomcols) {
        this.alArticulos = alArticulos;
        this.nomcols = nomcols;
    }
    
    @Override
    public int getRowCount() {
       return alArticulos.size();
    }

    @Override
    public int getColumnCount() {
        return nomcols.size();
    }

    @Override
    public Object getValueAt(int row, int col) {
        Articulos a = alArticulos.get(row);
        Object retorno;
        
        if (col == 0) {
            return retorno = a.getIdArticulo();
        }else if(col == 1){
            return retorno = a.getAlmacen().getIdAlmacen();
        }else if(col == 2){
            return retorno = a.getDescripcion();
        }else if(col == 3){
            return retorno = a.getCantidad();
        }else if(col == 4){
            return retorno = a.getPrecio();
        }else{
            return null;
        }
    }

    @Override
    public String getColumnName(int col) {
        if (col == 0) {
            return nomcols.get(col);
        }else if(col == 1){
            return nomcols.get(col);
        }else if(col == 2){
            return nomcols.get(col);
        }else if(col == 3){
            return nomcols.get(col);
        }else if(col == 4){
            return nomcols.get(col);
        }else{
            return null;
        }
    }

    public void setAlArticulos(ArrayList<Articulos> alArticulos) {
        this.alArticulos = alArticulos;
    }
}
